---
import { type CollectionEntry, getCollection } from "astro:content";
import Comments from "../../components/Comments.astro";
import Layout from "../../layouts/BaseLayout.astro";

type Props = CollectionEntry<"blog">;

export async function getStaticPaths() {
	const posts = await getCollection("blog");

	return posts.map((post) => ({
		params: { slug: post.slug },
		props: post,
	}));
}

const post = Astro.props;
const { Content, remarkPluginFrontmatter } = await post.render();
---

<style>
	.header {
		text-align: center;
	}
</style>

<Layout description={post.data.description} title={post.data.title}>
	<article>
		<section class="header">
			<h1>{post.data.title}</h1>
			<p>
				<small>
					Posted
					<time datetime={post.data.pubDate.toISOString()}>{post.data.pubDate.toDateString()}</time>
					&nbsp;by&nbsp;{post.data.author}&nbsp;‐
					<strong>{remarkPluginFrontmatter.minutesRead}</strong>
				</small>
			</p>
		</section>

		<section>
			<Content />
		</section>

		<section>
			<Comments />
		</section>
	</article>
</Layout>